/**
 * Copyright (C) 2009 aileron.cc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package cc.aileron.orm;

import cc.aileron.orm.factory.serial.G2DaoSerial;
import cc.aileron.orm.factory.serial.G2DaoSerialGeneratedKeys;
import cc.aileron.orm.factory.serial.G2DaoSerialNoneGeneratedKeys;

/**
 * @author Aileron
 * 
 */
/**
 * DbName
 * 
 * @author aileron
 * 
 */
public enum G2DbName
{
    /**
     * mysql
     */
    MYSQL,

    /**
     * h2
     */
    H2,

    /**
     * postgresql
     */
    POSTGRESQL,

    /**
     * unknown
     */
    UNKNOWN;

    /**
     * @param value
     * @return DbName
     */
    public static G2DbName convert(final String value)
    {
        try
        {
            return valueOf(value.toUpperCase());
        }
        catch (final Exception e)
        {
            throw new NotSupportDataBase(value);
        }
    }

    /**
     * @return シリアル関連のクラス
     */
    public Class<? extends G2DaoSerial> getSerial()
    {
        switch (this)
        {
        case POSTGRESQL:
            return G2DaoSerialNoneGeneratedKeys.class;

        case H2:
        case MYSQL:
            return G2DaoSerialGeneratedKeys.class;

        default:
            return null;
        }
    }
}

/**
 * G2Daoサポート対象外のDB
 * 
 * @author Aileron
 */
class NotSupportDataBase extends Error
{
    private static final long serialVersionUID = -3903618007455579333L;

    public NotSupportDataBase(final String name)
    {
        super(name);
    }

}